<?php

class Util_Notice{
    public static function addNotice($send,$receive,$message){
        $data = array(
            'sendUser'=>$send,
            'receiveUser'=>$receive,
            'type'=>0,
            'message'=>$message,
            'created'=>time(),
        );
        list($insert_id, $rows) = DB::insert('mod_notice')
            ->columns (array_keys($data))
            ->values (array_values($data))
            ->execute();
        return $insert_id > 0;
    }

    public static function noticeList($limit=10,$offset = 0){
        $user = user::currentUser();
        $uid = $user->getUserUid();

        $query = DB::select()
            ->from('mod_notice')
            ->where('receiveUser','=',$uid)
            ->or_where('receiveUser','=',0)
            ->order_by('created','desc');
        $count = $query->execute()->count();
        $query = $query->limit($limit)->offset($offset);

        $query = $query->execute()->as_array();
        $list = array();
        foreach($query as $v){
            if($v['sendUser'] == '-10'){
                $v['name'] = '哇吖官方';
                $v['icon'] = "/resource/www/imgs/default_user_tx.png";
            }else{
                $data = Util_User::getUserInfo($v['sendUser']);
                $v['name'] = $data['userFamily'].$data['userName'];
                $v2 = Util_User::getUserInfo($v['sendUser']);
                $v['icon'] = Arr::get($v2,'userIcon','/resource/skin/img/index_mingxing.png');

            }
            if($v['receiveUser'] == 0){
                $time = DB::select()
                    ->from('notice_read')
                    ->where('uid','=',$uid)
                    ->order_by('created','desc')
                    ->limit(1)
                    ->execute()
                    ->get('created');

                $v['undel'] = 1;
                if($v['created'] < $time){
                    $v['type'] = 1;
                }
            }

            $v['created'] = date('Y.m.d H:i',$v['created']);
            $list[] = $v;

        }
        return array($count,$list);


    }

    public static function noticeDetail($nid){
        $notice = DB::select()
            ->from('mod_notice')
            ->where('id','=',$nid)
            ->execute()
            ->current();

        $notice['created'] = date('Y.m.d H:i:s',$notice['created']);
        $insert_id = 0;
        if($notice['receiveUser'] != 0){
            $save['type'] = 1;
            $insert_id = self::update($save,'id',$nid);

        }else{
            $user = user::currentUser();
            $uid = $user->getUserUid();
            $data['uid'] = $uid;
            $data['created'] = time();
            list($insert_id,$row) = DB::insert('notice_read')
                ->columns(array_keys($data))
                ->values(array_values($data))
                ->execute();
        }

        return $insert_id > 0;
    }

    public static function update($data,$key,$val){
        $rows = DB::update('mod_notice')
            ->set($data)
            ->where($key, '=', $val)
            ->execute();
        return $rows;
    }

    public static function remove($nid){
        $data = DB::delete('mod_notice')
            ->where('id','=',$nid)
            ->execute();
        return $data > 0;
    }

    public static function notice_unread($uid){
        if(empty($uid)){
            return 0;
        }

        $query = DB::select()
            ->from('mod_notice')
            ->where('type','=',0)
            ->where('receiveUser','=',$uid)
            ->execute()
            ->count();

        $time = DB::select()
            ->from('notice_read')
            ->where('uid','=',$uid)
            ->order_by('created','desc')
            ->limit(1)
            ->execute()
            ->get('created');
        $time = $time == NULL ? 0:$time;
        $count2 = DB::select()
            ->from('mod_notice')
            ->where('receiveUser','=','0')
            ->where('created','>',$time)
            ->execute()
            ->count();



        return $query+$count2;
    }

    public static function notice_list($limit=20,$offset=0){
        $count = DB::select()
            ->from('mod_notice')
            ->where('receiveUser','=',0)
            ->execute()
            ->count();
        $query = DB::select()
            ->from('mod_notice')
            ->where('receiveUser','=',0)
            ->order_by('created','desc')
            ->limit($limit)
            ->offset($offset)
            ->execute()
            ->as_array();

        return array($count,$query);
    }

    public static function getNoticeById($id){
        return DB::select()
            ->from('mod_notice')
            ->where('id','=',$id)
            ->execute()
            ->current();
    }

    public static function notice_refund_front($orderDetail){
        $guider = Arr::get($orderDetail,'guider');
        $tourist = Arr::get($orderDetail,'tourist');
        $guider_id = Arr::get($guider,'userUid');
        $tourist_id = Arr::get($tourist,'userUid');
        $title = Arr::get($orderDetail,'title');
        $touristName = Arr::get($tourist,'userFamily').Arr::get($tourist,'userName');
        $guiderName = Arr::get($guider,'userFamily').Arr::get($guider,'userName');
        $startDay = Arr::get($orderDetail,'startDay');
        $endDay = Arr::get($orderDetail,'stopDay');

        $guider_msg = "{$touristName}针对{$startDay}至{$endDay}的行程《{$title}》向您发出了申诉，哇吖将在近期协调处理";
        $tourist_msg = "哇吖已收到您关于{$guiderName}提供的{$startDay}至{$endDay}的行程《{$title}》的申诉，哇吖将在近期协调处理";

        Util_Notice::addNotice($tourist_id, $guider_id, $guider_msg);
        Util_Notice::addNotice($tourist_id, $tourist_id, $tourist_msg);
    }

    public static function notice_refund_backend($orderNo){
        $detail = Order::detail($orderNo);
        $tourist = Arr::get($detail,'tourist');
        $guider = Arr::get($detail,'guider');
        $touristName = Arr::get($tourist,'userName');
        $startDay = Arr::get($detail,'startDay');
        $stopDay = Arr::get($detail,'stopDay');
        $title = Arr::get($detail,'title');
        $guider_msg = "{$touristName}关于{$startDay}至{$stopDay}《{$title}》行程的申诉已处理。";
        $tourist_msg = "您关于{$startDay}至{$stopDay}《{$title}》行程的申诉已处理。";
        $tourist_id = Arr::get($detail,'uid');
        $guider_id = Arr::get($detail,'shopId');

        self::addNotice(-10,$guider_id,$guider_msg);
        self::addNotice(-10,$tourist_id,$tourist_msg);

        $tourist = Util_User::getUserInfo($tourist_id);
        $mobile_tourist = Arr::get($tourist,'userPhone');
        if($mobile_tourist != ''){
            $tpl_id = 1196617;
            $tpl_value = "#start_date#={$startDay}&#end_date#={$stopDay}&#service#={$title}";
            $sms_obj = new Util_YunPianSms();
            $sms_obj->send_sms_to_user_id($tpl_id, $tpl_value, $mobile_tourist);
        }

        $mail_tourist = Arr::get($tourist,'mail');
        $mail_guider = Arr::get($guider,'email');
//        $startDay =date("Y年m月d日",strtotime($startDay));
//        $stopDay = date("Y年m月d日",strtotime($stopDay));
        $mail_body = <<<DOC
<meta charset="utf-8">
<style type="text/css">
body{ margin:0 auto; padding:0; font-family:'微软雅黑',Hiragino Sans GB', '华文细黑', 'STHeiti', 'Microsoft YaHei',
SimHei, 'Helvetica Neue', Helvetica, Arial, sans-serif;background-color:#fff; font-size:12px;}

a{color:#00a2ca; line-height:22px; text-decoration:none;}
a:hover{text-decoration:underline;color:#489E85;}
td{font-family:'微软雅黑i';}
</style>


<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" style="font-family:'微软雅黑';">
<tbody>
<tr>
        <td>
             <table style="width:800px;height:149px;">
             <tbody>
            <tr>
            <td><img src="http://www.wayatrip.com/resource/images/mail-imgs2.png" style="width:800px;height:149px;"></td>
            </tr>
             </tbody></table>
       </td>
</tr>

<tr>
        <td>
             <table style="width:800px;height:20px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>

            <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#fff" height="74" style="font-family:'微软雅黑';">
              <tbody><tr>
                <td width="97" height="74" border="0" align="center" valign="middle" style="padding-left:20px;"><a href="http://www.wayatrip.com" target="_blank"><img src="http://www.wayatrip.com/resource/www/imgs/logo.png" alt="哇吖自由行" width="97" height="74" border="0"></a>
               </td>
                <td width="703" height="74" colspan="2" align="left" valign="middle" style="padding-left:30px;">
                <font style="font-size:30px;color:#489E85;"><strong>申诉处理</strong></font>
                </td>
              </tr>
            </tbody></table>

        </td>
</tr>

<tr>
        <td>
             <table style="width:800px;height:20px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table align="center" cellpadding="0" cellspacing="0" style="width:640px;height:30px;background-color:#96EDCC;border:1px solid #96EDCC;border-top-left-radius:6px;
border-top-right-radius:6px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table align="center" cellpadding="0" cellspacing="0" style="width:640px;height:100px;border:1px solid #96EDCC;
background-color:#96EDCC;color:#393939">
             <tbody>
            <tr>
            <td width="640" height="100" align="left" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">
            {$touristName}&nbsp;先生/女士:<br/><br/>关于<font style="font-size:30px;color:#146DF3">
            {$startDay}-{$stopDay}&nbsp;{$title}</font>&nbsp;申诉已处理完毕。<br/><br/>对于旅行中给您带来的不便，哇吖向您表示诚挚的歉意，希望您能够继续支持我们！</td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table align="center" cellpadding="0" cellspacing="0" style="width:640px;height:30px;background-color:#96EDCC;border:1px solid #96EDCC;border-bottom-left-radius:6px;
border-bottom-right-radius:6px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:50px;">
             <tbody>
            <tr>
            <td width="800" height="50"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:50px;text-align:center;vertical-align:middle">
             <tbody>
            <tr>
            <td style="font-size:15px;">如遇任何问题，请联系哇吖客服&nbsp;&nbsp;<font style="font-size:20px;color:#96EDCC">400-889-7955</font></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:30px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table width="800" height="200" cellpadding="0" cellspacing="0" style="background-color:#252525;color:#fff;">
             <tbody>
            <tr>
            <td width="175" height="200"></td>
            <td>
            <table style="height:225px;width:200px;color:#fff;">
             <tbody>
            <tr>
            <td width="200" height="50" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">联系我们</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">国内：400-889-7955</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">法国：+33666015304</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">邮箱：info@wayatrip.com</td>
            </tr>
            <tr>
            <td width="200" height="60" align="left" ></td>
            </tr>
            </tbody></table>
           </td>
           <td>
            <table style="height:250px;width:200px;color:#fff;">
             <tbody>
            <tr>
            <td width="200" height="50" align="center" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';padding-top:10px;color:#fff;">官方微信<br/>wayaziyouxing</td>
            </tr>
            <tr>
            <td width="200" height="100" align="center"><img src="http://www.wayatrip.com/resource/www/imgs/erweima.jpg" style="height:100px;width:100px"></td>
            </tr>
            <tr>
            <td width="200" height="50" ></td>
            </tr>
            </tbody></table>
           </td>
           <td width="150" height="200"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
</tbody></table>
DOC;



//        $mail_body = "{$touristName}关于{$startDay}至{$stopDay} {$title}的申诉已处理。";


        if(!empty($mail_tourist)){
            User_Subscribe::post_email($mail_tourist,'申诉处理成功',$mail_body);
        }

        if(!empty($mail_guider)){
            User_Subscribe::post_email($mail_guider,'申诉处理成功',$mail_body);
        }

    }

    public static function notice_confirm_order($orderNo){
        $detail = Order::detail($orderNo);

        $touristUid = Arr::get($detail,'uid');
        $tourist = Util_User::getUserInfo($touristUid);

        $startDay = Arr::get($detail,'startDay');
        $stopDay = Arr::get($detail,'stopDay');
        $title = Arr::get($detail,'title');
        $tourist_msg = "您已顺利完成{$startDay}至{$stopDay}《{$title}》，别忘了到个人中心我的点评中给哇吖玩伴点评哦！";
        self::addNotice(-10,$touristUid,$tourist_msg);
        $mobile = Arr::get($tourist,'userPhone');
        if(!empty($mobile)){
            $tpl_id = 1196621;
            $tpl_value = "#start_date#={$startDay}&#end_date#={$stopDay}&#service#={$title}";
            $sms_obj = new Util_YunPianSms();
            $sms_obj->send_sms_to_user_id($tpl_id, $tpl_value, $mobile);
        }
    }

    public static function notice_finish_to_guider($orderNo){
        $detail = Order::detail($orderNo);

        $guiderUid = Arr::get($detail,'shopId');
        $guider = Arr::get($detail,'guider');
        $tourist = Arr::get($detail,'tourist');

        $touristName = Arr::get($tourist,'userName');
        $guiderName = Arr::get($guider,'userName');
        $startDay = Arr::get($detail,'startDay');
        $stopDay = Arr::get($detail,'stopDay');
        $title = Arr::get($detail,'title');
        $moneyTotal = Arr::get($detail,'moneyTotal');
        $moneyTotal = $moneyTotal/100;
        $moneyTotalRMB = Arr::get($detail,'moneyTotalRMB')/100;
        $guider_msg = "哇吖已向您支付{$touristName} {$startDay}至{$stopDay}《{$title}》行程的费用{$moneyTotal}欧元（人民币{$moneyTotalRMB}元），请查收您的支付宝或是Paypal收款账户";

        self::addNotice(-10,$guiderUid,$guider_msg);

        $mobile = '+'.Arr::get($guider,'telCode').Arr::get($guider,'telNum');
        $mail = Arr::get($guider,'email');

        if(!empty($mobile)){
            $tpl_id = 1129969;
            $tpl_value = "#name#=Hi&#num#={$moneyTotal} euro";
            $sms_obj = new Util_YunPianSms();
            $rs = $sms_obj->send_sms_to_user_id($tpl_id, $tpl_value, $mobile);
            Kohana::$log->add(Log::ERROR, "sms:1129969 rs->". $rs . "val -> $tpl_value mobile -> $mobile");
        }

        if(!empty($mail)){
            $body = <<<DOC
<meta charset="utf-8">
<style type="text/css">
body{ margin:0 auto; padding:0; font-family:'微软雅黑',Hiragino Sans GB', '华文细黑', 'STHeiti', 'Microsoft YaHei',
SimHei, 'Helvetica Neue', Helvetica, Arial, sans-serif;background-color:#fff; font-size:12px;}

a{color:#00a2ca; line-height:22px; text-decoration:none;}
a:hover{text-decoration:underline;color:#489E85;}
td{font-family:'微软雅黑i';}
</style>


<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" style="font-family:'微软雅黑';">
<tbody>
<tr>
        <td>
             <table style="width:800px;height:149px;">
             <tbody>
            <tr>
            <td><img src="http://www.wayatrip.com/resource/images/mail-imgs2.png" style="width:800px;height:149px;"></td>
            </tr>
             </tbody></table>
       </td>
</tr>

<tr>
        <td>
             <table style="width:800px;height:20px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>

<tr>
        <td>

            <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#fff" height="74" style="font-family:'微软雅黑';">
              <tbody><tr>
                <td width="97" height="74" border="0" align="center" valign="middle" style="padding-left:20px;"><a href="http://www.wayatrip.com" target="_blank"><img src="http://www.wayatrip.com/resource/www/imgs/logo.png" alt="哇吖自由行" width="97" height="74" border="0"></a>
               </td>
                <td width="703" height="74" colspan="2" align="left" valign="middle" style="padding-left:30px;">
                <font style="font-size:30px;color:#489E85;"><strong>收款通知</strong></font>
                </td>
              </tr>
            </tbody></table>

        </td>
</tr>

<tr>
        <td>
             <table style="width:800px;height:20px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>


<tr>
        <td>
             <table align="center" cellpadding="0" cellspacing="0" style="width:640px;height:270px;border:1px solid #96EDCC;border-radius:6px;
background-color:#96EDCC;color:#393939">
             <tbody>
            <tr>
            <td width="640" height="100" align="left" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">
            哇吖已向您支付了&nbsp;<font style="font-size:30px">{$touristName}</font>&nbsp;先生/女士预定的:</td>
            </tr>
            <tr>
            <td width="640" height="70" align="center" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">
            <font style="font-size:30px">
           {$startDay}-{$stopDay}<br/>{$title}</font><br/>共计<font style="font-size:30px;color:#F05C92">&nbsp;{$moneyTotal}&nbsp;€</font>
            </td>
            </tr>
            <tr>
            <td width="640" height="100" align="center" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">
            请查收您的支付宝或是Paypal收款账户</td>
            </tr>
             </tbody></table>
       </td>
</tr>


<tr>
        <td>
             <table style="width:800px;height:30px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>

<tr>
        <td>
             <table style="width:800px;height:50px;text-align:center;vertical-align:middle">
             <tbody>
            <tr>
            <td style="font-size:15px;">如有任何问题，请发邮件至<br/><br/><font style="font-size:20px;color:#96EDCC;">customer@wayatrip.com</font></td>
            </tr>
             </tbody></table>
       </td>
</tr>

<tr>
        <td>
             <table style="width:800px;height:30px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table width="800" height="200" cellpadding="0" cellspacing="0" style="background-color:#252525;color:#fff;">
             <tbody>
            <tr>
            <td width="175" height="200"></td>
            <td>
            <table style="height:225px;width:200px;color:#fff;">
             <tbody>
            <tr>
            <td width="200" height="50" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">联系我们</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">国内：400-889-7955</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">法国：+33666015304</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">邮箱：info@wayatrip.com</td>
            </tr>
            <tr>
            <td width="200" height="60" align="left" ></td>
            </tr>
            </tbody></table>
           </td>
           <td>
            <table style="height:250px;width:200px;color:#fff;">
             <tbody>
            <tr>
            <td width="200" height="50" align="center" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';padding-top:10px;color:#fff;">官方微信<br/>wayaziyouxing</td>
            </tr>
            <tr>
            <td width="200" height="100" align="center"><img src="http://www.wayatrip.com/resource/www/imgs/erweima.jpg" style="height:100px;width:100px"></td>
            </tr>
            <tr>
            <td width="200" height="50" ></td>
            </tr>
            </tbody></table>
           </td>
           <td width="150" height="200"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
</tbody></table>
DOC;


//            $body = "哇吖已向您支付{$touristName} {$startDay}至{$stopDay} {$title}的费用{$moneyTotal}欧，请查收您的支付宝或是paypel收款账户。如有问题，请发邮件至customer@wayatrip.com";
            User_Subscribe::post_email($mail,'您的行程已完成',$body);
        }
    }

    public static function notice_message($tid,$gid,$type="TOURIST"){
        $tourist = Util_User::getUserInfo($tid);
        $guider = Util_User::getUserInfo($gid);
        $msg = "给您留言啦！";
        if($type == "GUIDER"){
            self::addNotice($gid,$tid,$msg);
        }else{
            self::addNotice($tid,$gid,$msg);
        }

        $tName = Arr::get($tourist,'userFamily').Arr::get($tourist,'userName');
        $gName = Arr::get($guider,'userFamily').Arr::get($guider,'userName');

        $t_email = Arr::get($tourist,'mail');
        $g_email = Arr::get($guider,'mail');

        $t_mobile = Arr::get($tourist,'userPhone');
        $g_mobile = Arr::get($guider,'userPhone');
        $time = date("Y.m.d H:i:s");

        if(!empty($t_mobile) && $type=='GUIDER'){
            $tpl_id = 1196619;
            $tpl_value = "#guide#={$gName}&#time#={$time}";
            $sms_obj = new Util_YunPianSms();
            $sms_obj->send_sms_to_user_id($tpl_id, $tpl_value, $t_mobile);
        }

        if(!empty($t_email) && $type=='GUIDER'){
            $address = url::site("/tourist/message", 'http', FALSE);
            $body = <<<DOC
<meta charset="utf-8">
<style type="text/css">
body{ margin:0 auto; padding:0; font-family:'微软雅黑','Hiragino Sans GB', '华文细黑', 'STHeiti', 'Microsoft YaHei',
SimHei, 'Helvetica Neue', Helvetica, Arial, sans-serif;background-color:#fff; font-size:12px;}

a{color:#00a2ca; line-height:22px; text-decoration:none;}
a:hover{text-decoration:underline;color:#489E85;}
td{font-family:'微软雅黑i';}
</style>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" style="font-family:'微软雅黑';">
<tbody>
<tr>
        <td>
             <table style="width:800px;height:149px;">
             <tbody>
            <tr>
            <td><img src="http://www.wayatrip.com/resource/images/mail-imgs2.png" style="width:800px;height:149px;"></td>
            </tr>
             </tbody></table>
       </td>
</tr>

<tr>
        <td>
             <table style="width:800px;height:20px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>

            <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#fff" height="74" style="font-family:'微软雅黑';">
              <tbody><tr>
                <td width="97" height="74" border="0" align="center" valign="middle" style="padding-left:20px;"><a href="http://www.wayatrip.com" target="_blank"><img src="http://www.wayatrip.com/resource/www/imgs/logo.png" alt="哇吖自由行" width="97" height="74" border="0"></a>
               </td>
                <td width="703" height="74" colspan="2" align="left" valign="middle" style="padding-left:30px;">
                <font style="font-size:30px;color:#489E85;"><strong>新留言</strong></font>
                </td>
              </tr>
            </tbody></table>

        </td>
</tr>

<tr>
        <td>
             <table style="width:800px;height:20px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>

<tr>
        <td>
             <table align="center" cellpadding="0" cellspacing="0" style="width:640px;height:100px;border:1px solid #96EDCC;border-radius:6px;
background-color:#96EDCC;color:#393939">
             <tbody>
            <tr>
            <td width="640" height="100" align="left" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">
            <font style="font-size:30px;">{$gName}</font>&nbsp;先生/女士，在北京时间&nbsp;<font style="font-size:30px">
           {$time}</font>&nbsp;&nbsp;给您留言啦！</td>
            </tr>

             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:50px;">
             <tbody>
            <tr>
            <td width="800" height="50"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
       <td>
       <table align="center" cellpadding="0" cellspacing="0" style="width:200px;height:50px;border:1px solid #F05C92;border-radius:4px;
background-color:#F05C92;vertical-align:middle;">
             <tbody>
            <tr>
            <td style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:60px;width:200px;height:50px;">
            <a href="{$address}" target="_blank" style="text-decoration:none;color:#fff;width:200px;height:50px;">查看留言</a>
            </td>
            </tr>
             </tbody></table>
       </td>

</tr>
<tr>
        <td>
             <table style="width:800px;height:30px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:50px;text-align:center;vertical-align:middle">
             <tbody>
            <tr>
            <td style="font-size:15px;">如无法点击，复制以下地址至浏览器打开<br/>{$address}</td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:30px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table width="800" height="200" cellpadding="0" cellspacing="0" style="background-color:#252525;color:#fff;">
             <tbody>
            <tr>
            <td width="175" height="200"></td>
            <td>
            <table style="height:225px;width:200px;color:#fff;">
             <tbody>
            <tr>
            <td width="200" height="50" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">联系我们</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">国内：400-889-7955</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">法国：+33666015304</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">邮箱：info@wayatrip.com</td>
            </tr>
            <tr>
            <td width="200" height="60" align="left" ></td>
            </tr>
            </tbody></table>
           </td>
           <td>
            <table style="height:250px;width:200px;color:#fff;">
             <tbody>
            <tr>
            <td width="200" height="50" align="center" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';padding-top:10px;color:#fff;">官方微信<br/>wayaziyouxing</td>
            </tr>
            <tr>
            <td width="200" height="100" align="center"><img src="http://www.wayatrip.com/resource/www/imgs/erweima.jpg" style="height:100px;width:100px"></td>
            </tr>
            <tr>
            <td width="200" height="50" ></td>
            </tr>
            </tbody></table>
           </td>
           <td width="150" height="200"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
</tbody></table>
DOC;

//            $body = "{$tName}在{$time}给您留言啦！快去看看吧！".url::site("/guider/message", 'http', FALSE)." ，如无法点击，请复制地址至浏览器打开。";
            User_Subscribe::post_email($t_email,'您收到了新的留言',$body);
        }

        if(!empty($g_email) && $type=='TOURIST'){
            $address = url::site("/guider/message", 'http', FALSE);
            $body = <<<DOC
<meta charset="utf-8">
<style type="text/css">
body{ margin:0 auto; padding:0; font-family:'微软雅黑',Hiragino Sans GB', '华文细黑', 'STHeiti', 'Microsoft YaHei',
SimHei, 'Helvetica Neue', Helvetica, Arial, sans-serif;background-color:#fff; font-size:12px;}

a{color:#00a2ca; line-height:22px; text-decoration:none;}
a:hover{text-decoration:underline;color:#489E85;}
td{font-family:'微软雅黑i';}
</style>


<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" style="font-family:'微软雅黑';">
<tbody>
<tr>
        <td>
             <table style="width:800px;height:149px;">
             <tbody>
            <tr>
            <td><img src="http://www.wayatrip.com/resource/images/mail-imgs2.png" style="width:800px;height:149px;"></td>
            </tr>
             </tbody></table>
       </td>
</tr>

<tr>
        <td>
             <table style="width:800px;height:20px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
            <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#fff" height="74" style="font-family:'微软雅黑';">
              <tbody><tr>
                <td width="97" height="74" border="0" align="center" valign="middle" style="padding-left:20px;"><a href="http://www.wayatrip.com" target="_blank"><img src="http://www.wayatrip.com/resource/www/imgs/logo.png" alt="哇吖自由行" width="97" height="74" border="0"></a>
               </td>
                <td width="703" height="74" colspan="2" align="left" valign="middle" style="padding-left:30px;">
                <font style="font-size:30px;color:#489E85;"><strong>新留言</strong></font>
                </td>
              </tr>
            </tbody></table>

        </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:20px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table align="center" cellpadding="0" cellspacing="0" style="width:640px;height:100px;border:1px solid #96EDCC;border-radius:6px;
background-color:#96EDCC;color:#393939">
             <tbody>
            <tr>
            <td width="640" height="100" align="left" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">
            <font style="font-size:30px;">{$tName}</font>&nbsp;先生/女士，在北京时间&nbsp;<font style="font-size:30px">
           {$time}</font>&nbsp;&nbsp;给您留言啦！</td>
            </tr>

             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:50px;">
             <tbody>
            <tr>
            <td width="800" height="50"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
       <td>
       <table align="center" cellpadding="0" cellspacing="0" style="width:200px;height:50px;border:1px solid #F05C92;border-radius:4px;
background-color:#F05C92;vertical-align:middle;">
             <tbody>
            <tr>
            <td style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:60px;width:200px;height:50px;">
            <a href="{$address}" target="_blank" style="text-decoration:none;color:#fff;width:200px;height:50px;">查看留言</a>
            </td>
            </tr>
             </tbody></table>
       </td>

</tr>
<tr>
        <td>
             <table style="width:800px;height:30px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:50px;text-align:center;vertical-align:middle">
             <tbody>
            <tr>
            <td style="font-size:15px;">如无法点击，复制以下地址至浏览器打开<br/>{$address}</td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:30px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table width="800" height="200" cellpadding="0" cellspacing="0" style="background-color:#252525;color:#fff;">
             <tbody>
            <tr>
            <td width="175" height="200"></td>
            <td>
            <table style="height:225px;width:200px;color:#fff;">
             <tbody>
            <tr>
            <td width="200" height="50" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">联系我们</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">国内：400-889-7955</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">法国：+33666015304</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">邮箱：info@wayatrip.com</td>
            </tr>
            <tr>
            <td width="200" height="60" align="left" ></td>
            </tr>
            </tbody></table>
           </td>
           <td>
            <table style="height:250px;width:200px;color:#fff;">
             <tbody>
            <tr>
            <td width="200" height="50" align="center" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';padding-top:10px;color:#fff;">官方微信<br/>wayaziyouxing</td>
            </tr>
            <tr>
            <td width="200" height="100" align="center"><img src="http://www.wayatrip.com/resource/www/imgs/erweima.jpg" style="height:100px;width:100px"></td>
            </tr>
            <tr>
            <td width="200" height="50" ></td>
            </tr>
            </tbody></table>
           </td>
           <td width="150" height="200"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
</tbody></table>
DOC;


//            $body = "{$gName}在{$time}给您留言啦！快去看看吧！ ".url::site("/tourist/message", 'http', FALSE)." ，如无法点击，请复制地址至浏览器打开。";
            User_Subscribe::post_email($g_email,'您收到了新的留言',$body);
        }
    }

}
